﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CSharp;
using StructureMap;
using StructureMap.Configuration.DSL;
using AutoMapper;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Engine;
using KCMS.BusinessLogic;
using KCMS.Web.Models;
using KCMS.BusinessLogic.Interfaces;
using KCMS.BusinessLogic.Engine;
using System.Web.Routing;
namespace KCMS.Bootstraper
{

    public class GlobalRegistry : Registry
    {
        public static void Initialize()
        {
            ObjectFactory.Initialize(x => x.AddRegistry(new GlobalRegistry()));
        }

        public GlobalRegistry()
        {
            //For<IFooDataAccess>().Use<FooDataAccess>();
            //For<IFooService>().Use<FooService>();
            For<IMailService>().Use<MailService>();
            For<ICartService>().Use<CartService>();
            For<ICalculator>().Use<Calculator>();

            For<INewsManager>().Use<NewsManager>();
            For<INewsService>().Use<NewsService>();

            For<IBrendManager>().Use<BrendManager>();
            For<IBrendService>().Use<BrendService>();

            For<ISettingsManager>().Use<SettingsManager>();
            For<ISettingsService>().Use<SettingsService>();

            For<IClientManager>().Use<ClientManager>();
            For<IClientService>().Use<ClientService>();

            For<IOrderDeliveryManager>().Use<OrderDeliveryManager>();
            For<IOrderDeliveryService>().Use<OrderDeliveryService>();

            For<IOrderManager>().Use<OrderManager>();
            For<IOrderService>().Use<OrderService>();

            For<IOrderStatusManager>().Use<OrderStatusManager>();
            For<IOrderStatusService>().Use<OrderStatusService>();

            For<IOrderItemManager>().Use<OrderItemManager>();
            For<IOrderItemService>().Use<OrderItemService>();

            For<IAllowableProductSizeManager>().Use<AllowableProductSizeManager>();
            For<IAllowableProductSizeService>().Use<AllowableProductSizeService>();

            For<ISizeManager>().Use<SizeManager>();
            For<ISizeService>().Use<SizeService>();

            For<IProductImageManager>().Use<ProductImageManager>();
            For<IProductImageService>().Use<ProductImageService>();

            For<IProductCategoryManager>().Use<ProductCategoryManager>();
            For<IProductCategoryService>().Use<ProductCategoryService>();

            For<IProductManager>().Use<ProductManager>();
            For<IProductService>().Use<ProductService>();
            For<IFilterProduct>().Use<FilterProduct>();
            //For<IPictureManager>().Use<PictureManager>();
            //For<IPictureService>().Use<PictureService>();


            For<IContactManager>().Use<ContactManager>();
            For<IContactService>().Use<ContactService>();

            For<IPageManager>().Use<PageManager>();
            For<IPageService>().Use<PageService>();

            For<IPageCategoryManager>().Use<PageCategoryManager>();
            For<IPageCategoryService>().Use<PageCategoryService>();

            For<IMenuManager>().Use<MenuManager>();
            For<IMenuService>().Use<MenuService>();

            For<IMenuItemManager>().Use<MenuItemManager>();
            For<IMenuItemService>().Use<MenuItemService>();



            Mapper.CreateMap
      <KCMS.DataAcsess.Entitys.NewsEntity,
      KCMS.BusinessLogic.Models.News>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.News,
                KCMS.DataAcsess.Entitys.NewsEntity>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.News,
               KCMS.Web.Models.NewsViewModel>();



            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.SettingsEntity,
                 KCMS.BusinessLogic.Models.Settings>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Settings,
                KCMS.DataAcsess.Entitys.SettingsEntity>();

            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.ClientEntity,
                KCMS.BusinessLogic.Models.Client>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Client,
                KCMS.DataAcsess.Entitys.ClientEntity>().ForMember("OrderEntities", opt => opt.Ignore());
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Client,
               KCMS.Web.Models.ClientViewModel>();
            Mapper.CreateMap<KCMS.Web.Models.ClientViewModel,
            KCMS.BusinessLogic.Models.Client>();

            Mapper.CreateMap
             <KCMS.DataAcsess.Entitys.OrderDeliveryEntity,
                 KCMS.BusinessLogic.Models.OrderDelivery>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.OrderDelivery,
                KCMS.DataAcsess.Entitys.OrderDeliveryEntity>()
                .ForMember("OrderEntities", opt => opt.Ignore());
            Mapper.CreateMap<KCMS.BusinessLogic.Models.OrderDelivery,
             KCMS.Web.Models.OrderDeliveryViewModel>();
            Mapper.CreateMap<KCMS.Web.Models.OrderDeliveryViewModel,
            KCMS.BusinessLogic.Models.OrderDelivery>();


            Mapper.CreateMap
      <KCMS.DataAcsess.Entitys.OrderStatusEntity,
      KCMS.BusinessLogic.Models.OrderStatus>()
      .ForMember(dst => dst.Order, opt => opt.MapFrom(src => src.OrderEntity));
            Mapper.CreateMap<KCMS.BusinessLogic.Models.OrderStatus,
                KCMS.DataAcsess.Entitys.OrderStatusEntity>().ForMember("OrderEntity", opt => opt.Ignore());


        Mapper.CreateMap
            <KCMS.DataAcsess.Entitys.AllowableProductSizeEntity,
            KCMS.BusinessLogic.Models.AllowableProductSize>()
            .ForMember(dst=>dst.Size,opt=>opt.MapFrom(src=>src.SizeEntity))
            .ForMember(dst=>dst.Product,opt=>opt.MapFrom(src=>src.ProductEntity));
        Mapper.CreateMap<KCMS.BusinessLogic.Models.AllowableProductSize,
            KCMS.DataAcsess.Entitys.AllowableProductSizeEntity>()
            .ForMember(dst=>dst.SizeEntity, opt => opt.Ignore())
            .ForMember(dst=>dst.ProductEntity, opt => opt.Ignore());
            


            Mapper.CreateMap
       <KCMS.DataAcsess.Entitys.SizeEntity,
       KCMS.BusinessLogic.Models.Size>();
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Size,
                KCMS.DataAcsess.Entitys.SizeEntity>()
                .ForMember("OrderItemEntities", opt => opt.Ignore())
            .ForMember("AllowableProductSizeEntities", opt => opt.Ignore());
            Mapper.CreateMap
          <KCMS.BusinessLogic.Models.Size,
          KCMS.Web.Models.SizeViewModel>();


            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.OrderItemEntity,
                KCMS.BusinessLogic.Models.OrderItem>()
                //.ForMember(dst => dst.Size, opt => opt.MapFrom(src => src.OrderEntity))
                //.ForMember(dst => dst.Product, opt => opt.MapFrom(src => src.ProductEntity))
                //.ForMember(dst => dst.ProductImage, opt => opt.MapFrom(src => src.ProductImageEntity));
                    .ForMember(dst => dst.Size, opt => opt.MapFrom(src => src.SizeEntity))
                    .ForMember(dst => dst.Product, opt => opt.MapFrom(src => src.ProductEntity))
                    .ForMember(dst => dst.ProductImage, opt => opt.MapFrom(src => src.ProductImageEntity));

            Mapper.CreateMap<KCMS.BusinessLogic.Models.OrderItem,
                KCMS.DataAcsess.Entitys.OrderItemEntity>()
                    .ForMember(dst => dst.OrderEntity, opt => opt.Ignore())
                    .ForMember(dst => dst.ProductEntity, opt => opt.Ignore())
                    .ForMember(dst => dst.ProductImageEntity, opt => opt.Ignore())
                    .ForMember(dst => dst.SizeEntity, opt => opt.Ignore());


            Mapper.CreateMap
              <KCMS.DataAcsess.Entitys.OrderEntity,
              KCMS.BusinessLogic.Models.Order>()
                  .ForMember(dst => dst.Client, opt => opt.MapFrom(src => src.ClientEntity))
                  .ForMember(dst => dst.OrderItems, opt => opt.Ignore())
                  .ForMember(dst => dst.Delivery, opt => opt.MapFrom(src => src.OrderDeliveryEntity));
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Order,
                KCMS.DataAcsess.Entitys.OrderEntity>()
                    .ForMember(dst => dst.ClientEntity, opt => opt.Ignore())
                    .ForMember("OrderItemEntities", opt => opt.Ignore())
                    .ForMember("OrderStatusEntities", opt => opt.Ignore())
                    .ForMember(dst => dst.OrderDeliveryEntity, opt => opt.Ignore());

            Mapper.CreateMap
          <KCMS.DataAcsess.Entitys.ProductImageEntity,
          KCMS.BusinessLogic.Models.ProductImage>()
                .ForMember(dst => dst.Product, opt => opt.MapFrom(x => x.ProductEntity));
            Mapper.CreateMap<KCMS.BusinessLogic.Models.ProductImage,
                KCMS.DataAcsess.Entitys.ProductImageEntity>()
                .ForMember(dst => dst.ProductEntity, opt => opt.Ignore())
                .ForMember("OrderItemEntities", opt => opt.Ignore());
            Mapper.CreateMap
          <KCMS.BusinessLogic.Models.ProductImage,
          KCMS.Web.Models.ProductImageViewModel>();


            Mapper.CreateMap
            <KCMS.DataAcsess.Entitys.ProductEntity,
            KCMS.BusinessLogic.Models.Product>()
                .ForMember(dst => dst.Index, src => src.MapFrom(x => x.Idx))
                .ForMember(dst => dst.Brend, opt => opt.MapFrom(src => src.BrendEntity))
                .ForMember(dst => dst.Category, opt => opt.MapFrom(src => src.ProductCategoryEntity));
            Mapper.CreateMap<KCMS.BusinessLogic.Models.Product,
                KCMS.DataAcsess.Entitys.ProductEntity>()
                .ForMember(dst => dst.Idx, src => src.MapFrom(x => x.Index))
                .ForMember(dst => dst.ProductCategoryEntity, opt => opt.Ignore())
                .ForMember("ProductImageEntities", opt => opt.Ignore())
                .ForMember("OrderItemEntities", opt => opt.Ignore())
                .ForMember(dst => dst.BrendEntity, opt => opt.Ignore())
                 .ForMember("AllowableProductSizeEntities", opt => opt.Ignore());

            Mapper.CreateMap
          <KCMS.BusinessLogic.Models.Product,
          KCMS.Web.Models.ProductViewModel>();

            Mapper.CreateMap
               <KCMS.DataAcsess.Entitys.ProductCategoryEntity,
               KCMS.BusinessLogic.Models.ProductCategory>();
            Mapper.CreateMap
                <KCMS.BusinessLogic.Models.ProductCategory,
                KCMS.DataAcsess.Entitys.ProductCategoryEntity>()
                .ForMember("ProductEntities", opt => opt.Ignore())
                .ForMember("ProductCategoryEntities", opt => opt.Ignore())
                .ForMember("ProductCategory1", opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.ProductCategory,
               KCMS.Web.Models.ProductCategoryViewModel>();

            //Mapper.CreateMap
            // <KCMS.DataAcsess.Entitys.PictureEntity,
            // KCMS.BusinessLogic.Models.Picture>();
            //Mapper.CreateMap
            //<KCMS.BusinessLogic.Models.Picture,
            //KCMS.DataAcsess.Entitys.PictureEntity>().
            //    ForMember("PhotoEntities", opt => opt.Ignore()).
            //    ForMember("PageCategoryEntities", opt => opt.Ignore()).
            //    ForMember("ProductEntity", opt => opt.Ignore());
            //          Mapper.CreateMap
            //<KCMS.BusinessLogic.Models.Picture,
            //KCMS.Web.Models.PictureViewModel>();



            Mapper.CreateMap
               <KCMS.DataAcsess.Entitys.BrendEntity,
               KCMS.BusinessLogic.Models.Brend>();
            Mapper.CreateMap
            <KCMS.BusinessLogic.Models.Brend,
            KCMS.DataAcsess.Entitys.BrendEntity>().ForMember("ProductEntities", opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.Brend,
               KCMS.Web.Models.BrendViewModel>();

            Mapper.CreateMap
               <KCMS.DataAcsess.Entitys.ContactEntity,
               KCMS.BusinessLogic.Models.Contact>();
            Mapper.CreateMap
            <KCMS.BusinessLogic.Models.Contact,
            KCMS.DataAcsess.Entitys.ContactEntity>();
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.Contact,
               KCMS.Web.Models.ContactViewModel>();


            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.PageEntity,
                KCMS.BusinessLogic.Models.Page>();
            Mapper.CreateMap
            <KCMS.BusinessLogic.Models.Page,
            KCMS.DataAcsess.Entitys.PageEntity>()
            .ForMember(dst => dst.PageCategoryEntity, opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.Page,
               KCMS.Web.Models.PageViewModel>();


            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.PageCategoryEntity,
                KCMS.BusinessLogic.Models.PageCategory>();
            Mapper.CreateMap
                <KCMS.BusinessLogic.Models.PageCategory,
                KCMS.DataAcsess.Entitys.PageCategoryEntity>()
                .ForMember("PageEntities", opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.PageCategory,
               KCMS.Web.Models.PageCategoryViewModel>();

            Mapper.CreateMap
                <KCMS.DataAcsess.Entitys.MenuItemEntity,
                KCMS.BusinessLogic.Models.MenuItem>().ForMember(dst => dst.Items, opt => opt.Ignore());
            Mapper.CreateMap
                <KCMS.BusinessLogic.Models.MenuItem,
                KCMS.DataAcsess.Entitys.MenuItemEntity>().ForMember("MenuEntity", opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.MenuItem,
               KCMS.Web.Models.MenuItemViewModel>().ForMember(dst => dst.RouteValues, opt => opt.Ignore())
               .ForMember(dst => dst.HtmlAttributes, opt => opt.Ignore());
            Mapper.CreateMap
          <KCMS.DataAcsess.Entitys.MenuEntity,
          KCMS.BusinessLogic.Models.Menu>().ForMember(dst => dst.Items, opt => opt.Ignore());
            Mapper.CreateMap
         <KCMS.BusinessLogic.Models.Menu,
            KCMS.DataAcsess.Entitys.MenuEntity>().ForMember("MenuItemEntities", opt => opt.Ignore());
            Mapper.CreateMap
               <KCMS.BusinessLogic.Models.Menu,
               KCMS.Web.Models.MenuViewModel>();

            /*.ForMember(dst => dst.intField, src => src.MapFrom<int>(x => x.intField))
            .ForMember(dst => dst.stringField, src => src.MapFrom<String>(x => x.stringField));*/

            Mapper.AssertConfigurationIsValid();
        }
    }
}
